import request from "../../../../Resources/utils/axios";
//request(path, method, data, transfer, successCallback, errorCallback, returnAllData = false) {

function fetch(url, method, params, orgin = false) {
	if (method.toLocaleLowerCase() == "get") {
		params = params;
	} else {
		params = { body: params, _request_content_type: "body" };
	}
	return new Promise((resolve, reject) => {
		request(
			url,
			method,
			params,
			true,
			response => {
				resolve(response);
			},
			err => {
				reject(err);
			},
			orgin
		);
	});
}




/**
 * 创建用户
 * @param {} data
 */
export function createUser(data) {
	return fetch("/uaa/api/users/role-info", "POST", {
		role: "patient",
		patientInfo: data
	});
}

/**
 * 获取用户详情
 * @param {} data
 */
export function getUser(id) {
	return fetch(`/uaa/api/users/role-info?role=patient&id=${id}`, "GET");
	// return fetch(`/uaa/api/users/role-info`, "GET", {
	// 	role: "patient",
	// 	id: "5aa8fc28f9054a000636b775"
	// });
}

/**
 *更新用户信息
 * @param {Object} data
 */
export function updateUser(id, data) {
	return fetch("/uaa/api/users/role-info", "PUT", {
		role: "patient",
		id,
		patientInfo: data
	});
}

/**
 *获取所有用户
 * @param {*} data //data格式：{pageIndex:'',pageSize:''}
 */
export function getAllUsers(data) {
	return fetch("/uaa/api/users/role-info-list", "GET", {
		role: "patient",
		...data
	});
}

/**
 * 获取指定id记录病例详情
 */
export function getCaseDetail(id) {
	return fetch(`/medicalrecords/api/record/${id}`, "GET");
}

/**
 * 获取所有病种
 */
export function getIllTypes() {
	return fetch("/medicalrecords/api/record-template/constant", "GET");
}

/**
 * 获取病种模板内容
 * @param {String} illType
 */
export function getTemplateDetail(illType) {
	return fetch(`/medicalrecords/api/record-template/ill/${illType}`, "GET");
}

/**
 * 保存或新建一条病例记录
 * @param {String，Number} id 如果id有值，则为更新，反之为新建
 * @param {String，Number} templateId 病种模板id
 * @param {String，Number} patientId	患者id
 * @param {Array} value
 * @param {Object} property 需要添加到列表显示的字段组
 */
export function saveCasedetail(
	id,
	templateId,
	templateName,
	patientId,
	value,
	property
) {
	return fetch(`/medicalrecords/api/record/`, !id ? "POST" : "PUT", {
		id,
		templateId,
		templateName,
		patientId,
		forms: value,
		property
	});
}

export function getAllCases(data) {
	return fetch("medicalrecords/api/record/form/list", "GET", data);
}
